import * as React from 'react';
import './hello.css';//方法1
// import style from "./hello.css";
// const style = require('./hello.css');//方法2
//引入
const imgX = require('../img/x.png');
export interface Props {
  name?: string;
  enthusiasmLevel?: number;
  onIncrement?: () => void;
  onDecrement?: () => void;
}

export default class Hello extends React.Component<Props,Object> {
    constructor(props: Props) {
      super(props);
    }
    render() {
      const { name, enthusiasmLevel = 1, onIncrement, onDecrement } = this.props;
  
      if (enthusiasmLevel <= 0) {
        throw new Error('You could be a little more enthusiastic. :D');
      }
  
      return (
        <div>
          <div className="hello">
            Hello {name + getExclamationMarks(enthusiasmLevel)}
          </div>
          <div>
            <button onClick={onDecrement}>-</button>
            <button onClick={onIncrement}>+</button>
          </div>
          <img src={imgX} alt="imgX"/>  
        </div>
        
      );
    }
  }

function getExclamationMarks(numChars: number) {
  return Array(numChars + 1).join('!');
}